//商品详情 仓库
import {reqAddOrUpdataCart, reqGoodInfo} from "@/api";
import {getUUID} from '@/utils/uuid_token'

const state={
    goodInfo:{},
    //添加一个临时id,游客id,并注册到requests的header中，请求头字段userTempId
    uuid_token:getUUID(),
}
const actions={
    async GoodInfo(context,value){
        const result= await reqGoodInfo(value);
        if(result.code==200){
            context.commit('GOODINFO',result.data)
        }
    },
    async addOrUpdateShopCart(context, {skuId,skuNum}){
        const result=await reqAddOrUpdataCart(skuId,skuNum)
        if(result.code==200){
            return 'ok'
        }else{
            return Promise.reject(new Error('fail'));
        }
    }
}
const mutations={
    GOODINFO(state,value){
        state.goodInfo=value;
    }
}
const getters={
    categoryView(){
        return state.goodInfo.categoryView||{};
    },
    skuInfo(){
        return state.goodInfo.skuInfo||{};
    },
    spuSaleAttrList(){
        return state.goodInfo.spuSaleAttrList||[];
    }
}
export default {
    state,
    actions,
    mutations,
    getters
}
